<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/public/header.jsp"%>
<%@ page import="com.beaut.project.util.FlowUtility" %>
<%@ page import="com.beaut.project.util.StaticData" %>
<html>
	<head>
		<title>员工考勤管理</title>
	<script type="text/javascript">
		$(function(){
			$("#leaveManage").layout();
			
			$("#searchValue").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch();
		       	} 
		   	}); 
			
			$("#type_id").combotree({
				url:'<%=contextPath %>/springMVC/group/getSystemTypeTree?type=10',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch();
				}
			});
// 			$("#dept_id").combotree({
// 				url:'<%=contextPath %>/springMVC/group/listDepartment',
// 				method:'POST',
// 				animate:true,
// 				lines:true,
// 				onChange:function(){
// 					doSearch();
// 				}
// 			});
			jQuery("#searchValue2").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch2();
		       	} 
		   	}); 
			jQuery('#person_id').combogrid({
				title:'请假人选择',
				mode:"remote",
				loadMsg:'正在加载数据，请稍后......',
				panelWidth:550,
				panelHeight:400,
				url:"<%=contextPath%>/springMVC/group/listPageUser",
				idField:"id",
				textField:"truename",
				rownumbers:true,
				fitColumns:true,
				columns: [[
					{field:'id',hidden:true},
					{field:'deptId',hidden:true},
					{field:'truename',title:'姓名',width:100},
					{field:'deptName',title:'所属部门',width:100},
					{field:'privName',title:'角色',width:100}
				]],
				toolbar:"#tba",
				pageSize:10,
				pageList:[10,50,100],  
				pagination:true,
				onChange:function(){
					doSearch();
				}
			});
			jQuery("#p_dept_id").combotree({
				url:'<%=contextPath %>/springMVC/group/listDepartment',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch2();
				}
			});
			$('#table').datagrid({
				title:'员工考勤管理',
				rownumbers:true,
				url:'<%=contextPath %>/springMVC/oa/listPageLeave',
				loadMsg:'正在加载数据，请稍后......',
				fitColumns:true,
				nowrap:false,
				idField:'id',
				frozenColumns:[[
				    {title:'主键',field:'id',hidden:true}
				]],
				columns:[[
					{title:'序号',field:'number',width:100,align:'center',sortable: true,hidden:true},
					{title:'姓名',field:'person_name',width:200,align:'center'},
					{title:'所属部门',field:'dept_name',width:200,align:'center'},
					{title:'请假类别',field:'type_name',width:200,align:'center'},
					{title:'请假原因',field:'reason',width:200,align:'center'},
					{title:'请假时间',field:'leaveTime',width:100,align:'center'},
					{title:'销假时间',field:'destroyLeaveTime',width:100,align:'center'},
					{title:'当前状态',field:'status',hidden:true},
					{title:'当前状态',field:'status_desc',width:100,align:'center'},
					{title:'编辑',field:'edit',width:200,align:'center',formatter:function(value,rowData,rowIndex){
						if(rowData.status == '<%=com.beaut.project.util.StaticData.NEW_CREATE%>'){
                    	return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:addOrEditLeave(1,'"+rowData.id+"');\"/>&nbsp;&nbsp;"
                    		 +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-no' title='删除' onclick=\"javascript:deleteLeave('"+rowData.id+"');\"/>&nbsp;&nbsp;"
                    		  +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='提交确认' onclick=\"javascript:shenpi(this,'"+rowData.id+"');\"/>";
					}
					if(rowData.status == '<%=com.beaut.project.util.StaticData.NO_PASS%>'){
						return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:addOrEditLeave(1,'"+rowData.id+"');\"/>&nbsp;&nbsp;"
						      +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='提交确认' onclick=\"javascript:shenpi(this,'"+rowData.id+"');\"/>";
					}
                	return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='查看' onclick=\"javascript:addOrEditLeave(2,'"+rowData.id+"');\"/>&nbsp;&nbsp;"
				      +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审核查看' onclick=\"javascript:JqueryViewFlowView('"+encodeURIComponent("<%=FlowUtility.LEAVE_SHENPI%>")+"','"+rowData.id+"');\"/>";
					}}
					//,
					//{title:'销假操作',field:'destroy',width:200,align:'center',formatter:function(value,rowData,rowIndex){
					//	return "<input type='button'   style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details'   onclick=\"javascript:detailCustomer('"+ rowData.id +"');\">";
					//}}
				]],
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				toolbar:'#tb'
			});
		});
		
		
		function rtCallBack(){
			$('#table').datagrid('reload');
		}
		
		function deleteLeave(leaveId){
			var rows=$('#table').datagrid('getSelections');
			$.messager.confirm('确认','您确认删除该记录信息？',function(msg){
				if(msg){
					$.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/oa/deleteLeave",
						data:"leaveId="+leaveId,
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								warningInfo(rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}
		function addOrEditLeave(type,id){
			if(type==0){
				openDialogResize("<%=contextPath %>/springViews/oa/addOrEditLeave.jsp?callback=rtCallBack",1000, 800);
			}else if(type==1){
				openDialogResize('<%=contextPath %>/springViews/oa/addOrEditLeave.jsp?callback=rtCallBack&id='+id,1000, 800);
			}else{
				openDialogResize('<%=contextPath %>/springViews/oa/addOrEditLeave.jsp?isShow=1&callback=rtCallBack&id='+id,1000, 800);

			}
		}
		function shenpi(obj,id){
	    	//flowBusinessUrl获取审批业务记录的URL(可以是个组合参数字符串),moduleFlow获取工作流程的流程名称
	      var flowBusinessUrl="<%=contextPath %>/springViews/oa/addOrEditLeave.jsp?callback=rtCallBack&id="+id;
	      var param="flowBusinessUrl="+encodeURIComponent(flowBusinessUrl)+"&moduleFlow="+encodeURIComponent("<%=FlowUtility.LEAVE_SHENPI%>")+"&businessId="+id;
	      jQuery(obj).hide();
	      jQuery.ajax({
						type:'POST',
						url:'<%=contextPath %>/springMVC/workFlow/toShenpi',
						dataType:"JSON",
						data:param,
						success:function(rtJson){
							if (rtJson.rtState == '0'){
								openDialogResize(rtJson.rtData.url,1000,800);
								table_reload(rows.length);
							}else{
								warningInfo(rtJson.rtMsrg);
							}
							jQuery(obj).show();
						}
					});
	       
	    } 
		
		function doSearch()
		{
			var searchValue = $('#searchValue').val();
			var type_id = $('#type_id').combotree('getValue');
// 			var dept_id = $("#dept_id").combotree('getValue');
			var person_id = jQuery("#person_id").combotree('getValue');
			var start_date = $('#start_date').datebox('getValue');
			var end_date = $('#end_date').datebox('getValue');
			$('#table').datagrid('load',{
				searchValue:searchValue,
				type_id:type_id,
				person_id:person_id,
// 				dept_id:dept_id,
				start_date:start_date,
				end_date:end_date
				});
		}
		function doSearch2() {
			var dept_id = jQuery('#p_dept_id').combotree('getValue');
			var searchValue = jQuery('#searchValue2').val();
			jQuery('#person_id').combogrid("grid").datagrid('load', {
				searchValue : searchValue,
				dept_id:dept_id
			});
		}
		function ExcelOut(){
			var start_date = jQuery('#start_date').datebox('getValue');
			var end_date = jQuery('#end_date').datebox('getValue');
			var searchValue = jQuery('#searchValue').val();
			var type_id = jQuery("#type_id").combotree('getValue');
			var person_id = jQuery("#person_id").combotree('getValue');
			var param = "start_date="+start_date+"&end_date="+end_date+"&searchValue="+encodeURIComponent(searchValue)+"&type_id="+type_id+"&person_id="+person_id;
			window.open('<%=contextPath %>/springMVC/excel/listLeaveExcel?'+param);
		}
	</script>
	</head>
	<body style="height: 97%">
		<div id="leaveManage" class="easyui-layout" data-options="fit:true">
			<div region="center"  style="padding:5px;">
			    	<div id="table" data-options="fit:true"></div>
			    	<div id="tb" style="padding:3px;height:auto">
						<div style="float:left;">
							<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addOrEditLeave(0);">新增</a>
								<a href="javascript:void(0)" class="easyui-linkbutton" iconCls='icon-excel' plain="true"    onclick="ExcelOut();">导出Excel</a>
						</div>
						<div align="right">
							请假人：<input type="text" id="person_id" name="person_id"   style="width:100px"> &nbsp;&nbsp;
<!-- 							所属部门：<input  id="dept_id" name="dept_id" class="easyui-combotree">&nbsp;&nbsp; -->
							外出类别：<input  id="type_id" name="type_id" class="easyui-combotree" style="width:100px">
							开始日期: <input id="start_date" name="start_date" class="easyui-datebox" style="width:100px;"/>
							结束日期: <input id="end_date" name="end_date" class="easyui-datebox" style="width:100px;"/>&nbsp;&nbsp;
							查询条件：<input id="searchValue" name="searchValue" style="width:100px" title="请假事由"/>&nbsp;&nbsp;
							<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
						
						</div>
					</div>
		    </div>
		</div>
		<div id="tba" style="padding:3px;height:auto">
			<div align="right">
			             所属部门：<input  id="p_dept_id" name="p_dept_id"  style="width:150px"  class="easyui-combotree">
				查询条件：<input id="searchValue2" name="searchValue2" style="width:150px" title="用户名称或者用户真实姓名"/>
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch2();"></a>
			</div>
		</div>
	</body>
</html>